package com.zhuss.order.processor;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.order.order.SearchPrefundBo;
import com.zhuss.bean.vo.order.order.ListPrefundVo;
import com.zhuss.common.PageVo;
import com.zhuss.exception.DzcxException;
import com.zhuss.exception.ExceptionCode;
import com.zhuss.order.db.dao.ext.PrefundDao;
import com.zhuss.order.db.entity.Prefund;


/**
 * @description: 退款返回记录读
 * @author: zhushanshuo
 * @create: Fri Jan 15 22:17:59 CST 2021
 **/
@Component("prefundRead")
public class PrefundRead {
	
	@Autowired
	private PrefundDao prefundDao;
	
	/**
	 * 退款返回记录
	 * @return
	 */
	public Object listPrefund(List<Long> prefundIdList) {
		List<Prefund> result = prefundDao.listById(prefundIdList);
		return result;
	}
	
	
	/**
	 * 根据名字查询退款返回记录
	 * @param 
	 * @return
	 */
	public List<Prefund> list(String name) {
		List<Prefund> result = prefundDao.listByName(name);
		return result;
	}
	
	public List<Prefund> listNotId(String name, Long prefundId) {
		List<Prefund> result = new ArrayList<Prefund>();
		List<Prefund> list = list(name);
		for (Prefund c : list) {
			if (!c.getPrefundId().equals(prefundId)) {
				result.add(c);
				break;
			}
		}
		return result;
	}
	
	/**
	 * 退款返回记录 
	 * @return
	 */
	public Object listPrefundId() {
		List<Prefund> prefundList = prefundDao.listAll();
		List<Long> result = new ArrayList<>();
		transferListId(prefundList, result);
		return result;
	}
	
	private void transferListId(List<Prefund> prefundList, List<Long> result) {
		for (Prefund item : prefundList) {
			result.add(item.getPrefundId());
		}
	}


	/**
	 * 退款返回记录列表
	 * @param bo
	 * @return
	 */
	public Object list(SearchPrefundBo bo) {
		PageVo<ListPrefundVo> result = new PageVo<ListPrefundVo>();
        result.setPageNum(bo.getPageNum());
        result.setPageSize(bo.getPageSize());
        result.setItems(prefundDao.list(bo));
        result.setTotal(prefundDao.countList(bo));
		return result;
	}
	
	/**
	 * 退款返回记录详情
	 * @param prefundId
	 * @return
	 * @throws DzcxException
	 */
	public Object detail(Long prefundId) throws DzcxException {
		Object result = prefundDao.detail(prefundId);
		if (result == null) {
			throw new DzcxException(ExceptionCode.数据不存在);
		}
		return result;
	}
	
	

}
